package com.zbkj.crmeb.merchant.api.controller;


import com.crmeb.core.common.CommonResult;
import com.utils.CrmebUtil;
import com.zbkj.crmeb.merchant.api.request.BuyMemberRequest;
import com.zbkj.crmeb.merchant.api.response.InformationMemberResponse;
import com.zbkj.crmeb.merchant.api.response.MemberDetailsResponse;
import com.zbkj.crmeb.merchant.api.response.ShowMemberResponse;
import com.zbkj.crmeb.user.service.UserMemberRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 用户购买会员记录表 前端控制器
 * </p>
 *
 * @author wuzp
 * @since 2022-05-11
 */
@RestController
@RequestMapping("api/front/user/member")
@Api(tags = "用户 -- 会员")
public class FrontUserMemberRecordController extends ApiBaseController {

    @Autowired
    private UserMemberRecordService userMemberRecordService;

    @ApiOperation(value = "购买会员")
    @PostMapping(value = "/buy")
    public CommonResult<Object> buyMember(HttpServletRequest httpServletRequest, @RequestBody BuyMemberRequest request){
        request.setMerId(getMerId(httpServletRequest));
        request.setClientIp(CrmebUtil.getClientIp(httpServletRequest));
        return CommonResult.success(userMemberRecordService.buyMember(request));
    }

    /**
     * 付费会员：保存会员信息并且返回付费token和appid
     * @param httpServletRequest
     * @param request
     * @return
     */
    @ApiOperation(value = "连连购买会员")
    @PostMapping(value = "/lianlian/buy")
    public CommonResult<Object> buyMemberRecord(HttpServletRequest httpServletRequest, @RequestBody BuyMemberRequest request){
        request.setMerId(getMerId(httpServletRequest));
        request.setClientIp(CrmebUtil.getClientIp(httpServletRequest));
        return CommonResult.success(userMemberRecordService.buyMemberRecord(request));
    }

    /**
     * 免费会员：只保存会员信息
     * @param httpServletRequest
     * @param request
     * @return
     */
    @ApiOperation(value = "保存会员信息")
    @PostMapping(value = "/record/save")
    public CommonResult<Object> saveMemberRecord(HttpServletRequest httpServletRequest, @RequestBody BuyMemberRequest request){
        request.setMerId(getMerId(httpServletRequest));
        request.setClientIp(CrmebUtil.getClientIp(httpServletRequest));
        return CommonResult.success(userMemberRecordService.saveMemberRecord(request));
    }

    /**
     * 免费会员：只保存会员信息
     * @param httpServletRequest
     * @param request
     * @return
     */
    @ApiOperation(value = "保存调查问卷")
    @PostMapping(value = "/questionnaire/save")
    public CommonResult<Object> saveQuestionnaire(HttpServletRequest httpServletRequest, @RequestBody BuyMemberRequest request){
        request.setMerId(getMerId(httpServletRequest));
        request.setClientIp(CrmebUtil.getClientIp(httpServletRequest));
        return CommonResult.success(userMemberRecordService.saveQuestionnaire(request));
    }

    @ApiOperation(value = "是否展示会员")
    @GetMapping(value = "/show")
    public CommonResult<ShowMemberResponse> showMember(HttpServletRequest httpServletRequest){
        return CommonResult.success(userMemberRecordService.showMember(getMerId(httpServletRequest)));
    }

    @ApiOperation(value = "个人会员信息")
    @GetMapping(value = "/information")
    public CommonResult<InformationMemberResponse> informationMember(){
        return CommonResult.success(userMemberRecordService.informationMember());
    }

    @ApiOperation(value = "查询商户会员类型及权益信息")
    @GetMapping(value = "/getMemberDetails")
    public CommonResult<MemberDetailsResponse> getMemberDetails(HttpServletRequest servletRequest){
        return CommonResult.success(userMemberRecordService.getMemberDetails(getMerId(servletRequest)));
    }

}

